//
//  UITextField+Extension.m
//  titleButton
//
//  Created by apple on 2017/9/27.
//  Copyright © 2017年 铁科院. All rights reserved.
//

#import "UITextField+Extension.h"
static NSString * const KXPlaceholderColorKey = @"placeholderLabel.textColor";
@implementation UITextField (Extension)
- (void)setKx_placeholderColor:(UIColor *)kx_placeholderColor
{
    // 提前设置占位文字, 目的 : 让它提前创建placeholderLabel
    NSString *oldPlaceholder = self.placeholder;
    self.placeholder = @" ";
    self.placeholder = oldPlaceholder;
    
    // 恢复到默认的占位文字颜色
    if (kx_placeholderColor == nil) {
        kx_placeholderColor = [UIColor colorWithRed:0 green:0 blue:0.0980392 alpha:0.22];
    }
    
    // 设置占位文字颜色
    [self setValue:kx_placeholderColor forKeyPath:KXPlaceholderColorKey];
}

- (UIColor *)placeholderColor
{
    return [self valueForKeyPath:KXPlaceholderColorKey];
}

- (void)kx_setTextOffsetWithLeftViewRect : (CGRect)rect WithMode :(UITextFieldViewMode)mode
{
    UIView *view = [[UIView alloc]initWithFrame:rect];
    self.leftView = view;
    self.leftViewMode = mode; //枚举 默认为no 不显示leftView
}
@end
